import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'
import test from '@/components/test'
import register from '@/components/register'
import showcate from '@/components/showcate'
import Login from '@/components/Login'
import myprofile from '@/components/myprofile'
// 考试
import kaoshi_register from '@/components/kaoshi_register'
import KaoLogin from '@/components/KaoLogin'
import kaoshi_addgoods from '@/components/kaoshi_addgoods'
import goodslist from '@/components/goodslist'

import ks from '@/components/ks'
import addgoods from '@/components/addgoods'
import editgood from '@/components/editgood'
import comments from '@/components/comments'
import search from '@/components/search'
import rank from '@/components/rank'


Vue.use(Router)

var routes = [
        {
          path: '/rank',
          name: 'rank',
          component: rank
        },
        {
          path: '/search',
          name: 'search',
          component: search
        },
        {
          path: '/comments',
          name: 'comments',
          component: comments
        },
        {
          path: '/goodslist',
          name: 'goodslist',
          component: goodslist
        },
        {
          path: '/kaoshi_addgoods',
          name: 'kaoshi_addgoods',
          component: kaoshi_addgoods
        },
        {
          path: '/editgood',
          name: 'editgood',
          component: editgood
        },
        {
          path: '/addgoods',
          name: 'addgoods',
          component: addgoods
        },
        {
          path: '/ks',
          name: 'ks',
          component: ks
        },
        {
          path: '/KaoLogin',
          name: 'KaoLogin',
          component: KaoLogin
        },
        {
          path: '/kaoshi_register',
          name: 'kaoshi_register',
          component: kaoshi_register
        },
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/cart',
          name:'cart',
          component:cart
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/detail',
          name:'detail',
          component:detail
        },
        {
          path:'/mytest',
          name:'mytest',
          component:mytest
        },
        {
          path:'/test',
          name:'test',
          component:test
        },
        {
          path:'/register',
          name:'register',
          component:register
        },
        {
          path:'/showcate',
          name:'showcate',
          component:showcate
        },
        {
          path: '/Login',
          name: 'Login',
          component: Login
        },
        // 拦截器
        {
          path: '/myprofile',
          name: 'myprofile',
          component: myprofile,
          beforeEnter:(to,from,next) => {

            // 判断用户是否登录
            if(localStorage.getItem('username')){

              console.log('已登陆')
              next();

            }else{

              console.log("未登录")
              next('/Login');
              
            }
          }
        }
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
